<template>
	<view>
		<image src="/static/xgbj.png" class="qjimg" mode=""></image>
		<view class="title">
			<image @click="fanhui" src="/static/zfh.png" :style="'margin-top:'+top+'px;'" mode=""></image>
			<view class="toptit" style="opacity: 0;">
				今日巡更
			</view>
			<view class="" style="opacity: 0;">12</view>
		</view>
		<view class="top">
			<image src="/static/aqxglog.png" mode=""></image>
			<view class="top1">
				<view class="top1text">
					巡更详情
				</view>
				<view class="top1text1">
					请按详情完成巡更任务
				</view>
			</view>
		</view>
		<view class="box">
			<view class="box_1">
				<image :src="xungeng.user.headimgurl" mode=""></image>
				<view class="box_1-1">
					<view class="box_1-1text">
						巡更人 {{xungeng.user.personName}}
					</view>
					<view class="box_1-1text1">
						{{xungeng.user.hidephone}}
					</view>
				</view>
			</view>
			<view class="box_title">
				巡更任务
			</view>
			<view class="box_2">
				<view class="box_2text">
					巡检类型： <text>{{xungeng.type}}</text>
				</view>
				<view class="box_2text">
					巡检小区： <text>{{xungeng.communityName}}</text>
				</view>
				<view class="box_2text">
					巡检路线： <text>{{xungeng.title}}</text>
				</view>

			</view>

			<view class="" v-if="list" v-for="(item,index) in list" :key="index">
				<view class="box_title">
					巡更详情
				</view>
				<view class="box_2">
					<view class="box_2text">
						巡检类型： <text>{{xungeng.type}}</text>
					</view>
					<view class="box_2text">
						巡检小区： <text>{{xungeng.communityName}}</text>
					</view>
					<view class="box_2text">
						巡检路线： <text>{{xungeng.title}}</text>
					</view>
					<view class="box_2text">
						巡检时间： <text>{{item.ctime}}</text>
					</view>
					<view class="box_2text">
						巡检结果： <text>{{item.content}}</text>
					</view>
					<view class="box_2text">
						图片：
					</view>
					<view class="box_3" style="margin: 50rpx 0;">
						<image :src="item1" v-for="(item1,index1) in item.pics" :key="index1" mode="aspectFill"
							@click="yulan(item.pics,index1)"></image>
					</view>
				</view>
			</view>


			<view class="" v-if="needup==1&&state=='true'">
				<view class="box_title" style="border-left: 8rpx solid #34d6c0;">
					巡更上报
				</view>
				<view class="box_2">
					<view class="box_2text">
						巡检时间： 自动获取
					</view>
					<view class="box_2text">
						巡检结果： 请输入巡检结果
					</view>
				</view>
				<textarea class="texta" v-model="content" name="" id="" cols="30" rows="10"></textarea>
				<view class="box_3" style="width: 91%;">
					<image :src="item" v-for="(item,index) in tupian" :key="index" mode="aspectFill"></image>
					<image src="/static/jiatp.png" mode="" @click="chooseImage"></image>
				</view>

				<view class="button" @click="tijiao">
					确认上报
				</view>

			</view>
			<view class="" style="width: 40rpx;height: 40rpx;"></view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				top: 0,
				xungestate: 1,
				id: '',
				state: false,
				info: '',
				xungeng: '',
				needup: '',
				list: '',
				tupian: [],
				content: '',
				address: '',
			}
		},
		onLoad(e) {
			this.state = e.state
			this.id = e.id
			let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
			// this.CustomBar = menuButtonInfo.bottom * 1 + 10
			this.top = menuButtonInfo.top * 1 + 10
			this.getinfo()
			this.huoquaddress()
		},
		methods: {
			tijiao() {
				console.log('12321');
				// uni.getLocation({
				// 	type: 'wgs84',
				// 	fail: function(res) {
				// 		console.log('当前位置的经度：' + res.longitude);
				// 		console.log('当前位置的纬度：' + res.latitude);
				// 		console.log(res, 111);

				// 	}
				// });
				this.$post('wuyecenter/upxungeng', {
					id: this.id,
					content: this.content,
					pics: this.tupian,
					// lng: res.longitude,
					// lat: res.latitude
				}, res => {
					this.getinfo()
				})
			},
			huoquaddress() {
				this.$post('api/getuploadurl', {

				}, res => {
					this.address = res.data.url
					console.log(this.address);
				})
			},
			chooseImage() {
				var that = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera'], //从相册选择
					success: function(res) {
						// that.tupian = res.tempFilePaths
						that.uploadFile(res.tempFilePaths[0], '')
					}
				});
			},
			uploadFile(data, state) {
				var that = this
				uni.uploadFile({
					url: that.address, //仅为示例，非真实的接口地址
					filePath: data,
					name: 'file',
					fileType: 'image',
					formData: {
						'user': 'test'
					},
					success: (uploadFileRes) => {
						const tupian = JSON.parse(uploadFileRes.data)
						if (state) {
							that.xungeng.user.headimgurl = tupian.data.url
							console.log(tupian.data.url);
						} else {
							that.tupian.push(tupian.data.url)
						}


					}
				});
			},
			yulan(item, index) {
				console.log(index);
				uni.previewImage({
					urls: item,
					current: index,

				});
			},
			getinfo() {
				this.$post('wuyecenter/xungenginfo', {
					id: this.id
				}, res => {
					this.info = res.data
					this.xungeng = res.data.xungeng

					this.list = res.data.list
					this.needup = res.data.needup
				})
			},
			fanhui() {
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: rgb(255, 255, 255);
	}

	.qjimg {
		width: 750rpx;
		height: 603rpx;
		position: absolute;
		top: 0;
		z-index: -1;
	}

	.title {
		display: flex;
		justify-content: space-between;
		align-items: center;

		>image {
			width: 12rpx;
			height: 24rpx;
			margin-left: 30rpx;
		}
	}

	.top {
		display: flex;
		margin-left: 46rpx;
		margin-top: 50rpx;

		>image {
			width: 97rpx;
			height: 97rpx;
		}
	}

	.top1 {
		margin-left: 16rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.top1text {
		font-size: 30rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 50rpx;
	}

	.top1text1 {
		font-size: 22rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 50rpx;
	}

	.box {
		background-color: #FFFFFF;
		width: 90vw;
		margin: 30rpx auto;
		border-radius: 20rpx;
	}

	.box_1 {
		display: flex;
		align-items: center;
		padding: 20rpx;

		>image {
			width: 94rpx;
			height: 94rpx;
		}
	}

	.box_1-1 {
		margin-left: 10rpx;
	}

	.box_1-1text {
		font-size: 30rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #333333;
		// line-height: 20rpx;
	}

	.box_1-1text1 {
		font-size: 24rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #999999;
		// line-height: 20rpx;
	}

	.box_title {
		margin-top: 50rpx;
		border-left: 8rpx solid #4ab6f9;
		width: 160rpx;
		text-align: center;
		font-size: 30rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #333333;
		// line-height: 20rpx;
	}

	.box_2 {
		width: 91%;
		margin: 30rpx auto;
	}

	.box_2text {
		font-size: 24rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #999999;
		// line-height: 20rpx;
		margin: 30rpx 0;

		>text {
			color: #333333;
		}
	}

	.texta {
		width: 91%;
		height: 170rpx;
		margin: 0 auto;
		background-color: #f6f6f6;
	}

	.box_3 {
		width: 100%;
		margin: 50rpx auto;
		display: flex;
		// justify-content: space-evenly;
		flex-wrap: wrap;

		>image {
			margin: 2rpx;
			width: 200rpx;
			height: 200rpx;
		}
	}

	.button {
		width: 498rpx;
		height: 70rpx;
		margin: 0 auto;
		margin-top: 100rpx;
		color: #FFFFFF;
		text-align: center;
		background-color: #2e79f9;
		border-radius: 35rpx;
		line-height: 70rpx;
	}
</style>
